﻿var ns = namespace("kaskelot.sp.ui");

ns.prompts = function () {

	function showPrompt(options) {

		var defaults = {
			title: "",
			text: "",
			okFunction: function () { },
			cancelFunction: function () { }
		}

		var settings = $.extend({}, defaults, options);

		$("#prompt-form .text-container").html(settings.text);
		$("#prompt-form").dialog({
			autoOpen: true,
			modal: true,
			resizable: false,
			hide: 'fade',
			show: 'fade',
			width: 300,
			title: settings.title,
			buttons: {
				OK: function () {
					$(this).dialog("close");
					settings.okFunction();
				},
				Avbryt: function () {
					settings.cancelFunction();
					$(this).dialog("close");
				}
			},
			close: function () {
				//destroyAnyTinyMCE(this);
				$("#prompt-form").parent().unblock();
			}
		});
	}

	function showErrorPrompt(text, ok_function) {
		$("#error-prompt-form").attr("title", "Fel");
		$("#error-prompt-form .text-container").html("<p style='color: #ff0000; font-weight: bold; font-size:13px;'>" + text + "</p>");
		$("#error-prompt-form").dialog({
			autoOpen: true,
			modal: true,
			resizable: false,
			hide: 'fade',
			show: 'fade',
			width: 300,
			buttons: {
				OK: function () {
					$(this).dialog("close");
					if ($.isFunction(ok_function))
						ok_function();
				}
			},
			close: function () {
				//destroyAnyTinyMCE(this);
			}
		});
	}

	function showWarningPrompt(options) {

		var defaults = {
			title: "",
			text: "",
			okFunction: function () { }
		}

		var settings = $.extend({}, defaults, options);

		$("#error-prompt-form").attr("title", "Varning" + settings.title);
		//<img src='/_layouts/images/brc.pims.ui/icons/crisis-big-icon.png' style='float: left; padding-right: 10px' />
		$("#error-prompt-form .text-container").html("<p style='color: #000; font-weight: bold; font-size:13px;'>" + settings.text + "</p>");
		$("#error-prompt-form").dialog({
			autoOpen: true,
			modal: true,
			resizable: false,
			hide: 'fade',
			show: 'fade',
			width: 300,
			buttons: {
				OK: function () {
					settings.okFunction();
					$(this).dialog("close");
				}
			},
			close: function () {
				//destroyAnyTinyMCE(this);
			}
		});
	}

	return {
		showPrompt: showPrompt,
		showErrorPrompt: showErrorPrompt,
		showWarningPrompt: showWarningPrompt
	}
}();